package com.ls.pattern.template.jdbc.dao;

import com.ls.pattern.template.jdbc.entity.Member;
import com.ls.pattern.template.jdbc.framework.JdbcTemplate;

import javax.sql.DataSource;
import java.sql.ResultSet;
import java.util.List;

/**
 * @author 挥之以墨
 */
public class MemberDao extends JdbcTemplate {

    public MemberDao(DataSource dataSource) {
        super(dataSource);
    }

    public List<Member> selectAll() {
        String sql = "select * from t_member";

        return executeQuery(sql, (ResultSet rs, int rowNum) -> {
            Member member = new Member();
            Member.builder()
                    .username(rs.getString("username"))
                    .password(rs.getString("password"))
                    .age(rs.getInt("age"))
                    .addr(rs.getString("addr"))
                    .build();
            return member;
        }, null);
    }
}
